package com.witframework.dynoengine.tool.jspc;


import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AlaJSP extends HttpServlet
{

    private String getId()
    {
        String s = "";
        synchronized(SessionIdLock)
        {
            long l = System.currentTimeMillis();
            Random random = new Random();
            s = String.valueOf(l);
            for(int i = 1; i <= 6; i++)
                s = s + (int)(1.0D + 6D * random.nextDouble());

        }
        return s;
    }

    private String readFile(String s)
    {
        String s1 = "";
        String s3 = getFullPath(s);
        try
        {
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(s3)));
            String s2;
            while((s2 = bufferedreader.readLine()) != null) 
                s1 = s1 + s2 + NEWLINE;
            bufferedreader.close();
        }
        catch(Exception _ex)
        {
            return "CANNOT_READ " + s3;
        }
        return s1;
    }

    private Object[] getParamArray(String s, int i)
    {
        String s1 = s.trim();
        String s6 = ",";
        Vector vector = new Vector();
        if(s1.length() > 0)
        {
            if(s1.charAt(0) == '(')
                s1 = s1.substring(1);
            if(s1.endsWith(")"))
                s1 = s1.substring(0, s1.length() - 1);
            String s2 = s1.trim();
            if(s2.length() == 0 && i == 0)
                return null;
            String s4;
            if(s2.length() > 0)
            {
                if(s2.charAt(0) == '"')
                    s6 = "\"";
                else
                    s6 = ",";
                s4 = s2.substring(0, 1);
                s2 = s2.substring(1);
            } else
            {
                s4 = "";
            }
            for(; s2.length() > 0; s2 = s2.substring(1))
            {
                String s5 = s2.substring(0, 1);
                if(s5.charAt(0) == s6.charAt(0))
                {
                    if(s6.equals("\""))
                        s4 = s4 + s6;
                    vector.addElement(s4);
                    s2 = s2.substring(1).trim();
                    s4 = "";
                    if(s2.length() == 0)
                        break;
                    s4 = s2.substring(0, 1);
                    if(s4.charAt(0) == ',')
                    {
                        s2 = s2.substring(1).trim();
                        s4 = "";
                        if(s2.length() == 0)
                            break;
                        s4 = s2.substring(0, 1);
                    }
                    if(s4.charAt(0) == '"')
                        s6 = "\"";
                    else
                        s6 = ",";
                } else
                {
                    s4 = s4 + s5;
                }
            }

            if(s4.length() > 0)
                vector.addElement(s4);
        }
        int j = vector.size();
        if(j == 0 && i == 0)
            return null;
        Object aobj[] = new Object[3];
        Class aclass[] = new Class[j + i];
        Object aobj1[] = new Object[j + i];
        aobj[0] = aclass;
        aobj[1] = ((Object) (aobj1));
        aobj[2] = new Integer(j + i);
        for(int k = i; k < j + i; k++)
        {
            String s3 = (String)vector.elementAt(k - i);
            try
            {
                Integer integer = Integer.valueOf(s3);
                aclass[k] = Integer.TYPE;
                aobj1[k] = integer;
            }
            catch(Exception _ex)
            {
                try
                {
                    Float float1 = Float.valueOf(s3);
                    aclass[k] = Float.TYPE;
                    aobj1[k] = float1;
                }
                catch(Exception _ex2)
                {
                    s3 = prepareString(s3);
                    if(s3.equals("true"))
                    {
                        aclass[k] = Boolean.TYPE;
                        aobj1[k] = new Boolean(true);
                    } else
                    if(s3.equals("false"))
                    {
                        aclass[k] = Boolean.TYPE;
                        aobj1[k] = new Boolean(false);
                    } else
                    {
                        aclass[k] = java.lang.String.class;
                        aobj1[k] = s3;
                    }
                }
            }
        }

        vector = null;
        return aobj;
    }

    private synchronized Class loadClass(HttpServletRequest httpservletrequest, String s, String s1)
    {
        Object obj;
        try
        {
            if(s.indexOf("session") < 0)
            {
                synchronized(classesLock)
                {
                    if(classes == null)
                        classes = new Hashtable();
                    obj = classes.get(s1);
                    if(obj == null)
                    {
                        if((obj = (new NewLoader(CLASS_DIR)).loadClass(s1)) == null)
                            obj = Class.forName(s1);
                        classes.put(s1, obj);
                    }
                }
            } else
            {
                javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, true);
                if(httpsession == null)
                    return null;
                if((obj = sessions.getClassObject(httpsession, s1)) == null)
                {
                    if((obj = (new NewLoader(CLASS_DIR)).loadClass(s1)) == null)
                        obj = Class.forName(s1);
                    sessions.putClass(httpsession, s1, obj);
                }
            }
        }
        catch(Exception _ex)
        {
            return null;
        }
        return (Class)obj;
    }

    private synchronized void unloadClass(String s)
    {
        synchronized(objectsLock)
        {
            if(objects != null)
                objects.remove(s);
        }
        synchronized(classesLock)
        {
            if(classes == null)
                return;
            classes.remove(s);
        }
    }

    private synchronized Object createObjectInstance(HttpServletRequest httpservletrequest, String s, Class class1, String s1, String s2)
    {
        String s3 = class1.getName();
        String s4 = s1;
        String s5 = s2;
        Hashtable hashtable;
        if(s.indexOf("session") < 0)
        {
            synchronized(objectsLock)
            {
                if(objects == null)
                    objects = new Hashtable();
                hashtable = (Hashtable)objects.get(s3);
                if(hashtable == null)
                {
                    hashtable = new Hashtable();
                    objects.put(s3, hashtable);
                }
                Object obj = hashtable.get(s5);
                hashtable.remove(s5);
            }
        } else
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
            if(httpsession == null)
                return null;
            if((hashtable = sessions.getObjects(httpsession)) == null)
                return null;
            s5 = s3;
        }
        Object aobj[] = getParamArray(s4, 0);
        try
        {
            if(aobj == null)
            {
                Object obj1 = class1.newInstance();
                hashtable.put(s5, obj1);
                return obj1;
            }
            Constructor constructor = class1.getConstructor((Class[])aobj[0]);
            if(class1 == null)
            {
                return null;
            } else
            {
                Object obj2 = constructor.newInstance((Object[])aobj[1]);
                hashtable.put(s5, obj2);
                return obj2;
            }
        }
        catch(Exception _ex)
        {
            return null;
        }
    }

    private synchronized Object getObjectInstance(HttpServletRequest httpservletrequest, Class class1, String s, String s1)
    {
        if(s.indexOf("session") < 0)
        {
            if(objects == null)
                return null;
            Hashtable hashtable;
            if((hashtable = (Hashtable)objects.get(class1.getName())) == null)
                return null;
            Object obj = hashtable.get(s1);
            if(obj == null)
            {
                if(s1.compareTo("") != 0)
                    return hashtable.get("");
                else
                    return null;
            } else
            {
                return obj;
            }
        }
        javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
        if(httpsession == null)
            return null;
        else
            return sessions.getObjectInstance(httpsession, class1.getName());
    }

    private synchronized Object invokeObject(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, Class class1, Object obj, String s, String s1)
    {
        Object obj1 = null;
        Object obj2 = null;
        byte byte0 = 0;
        if(class1.getName().compareTo("stdlib") == 0)
            byte0 = 3;
        Object aobj[] = getParamArray(s1, byte0);
        if(byte0 == 3)
            try
            {
                ((Class[])aobj[0])[0] = java.lang.Object.class;
                ((Object[])aobj[1])[0] = httpservletrequest;
                ((Class[])aobj[0])[1] = java.lang.Object.class;
                ((Object[])aobj[1])[1] = httpservletresponse;
                ((Class[])aobj[0])[2] = java.lang.Object.class;
                ((Object[])aobj[1])[2] = printwriter;
            }
            catch(Exception _ex) { }
        try
        {
            Method method;
            if(aobj == null)
                method = class1.getMethod(s, null);
            else
                method = class1.getMethod(s, (Class[])aobj[0]);
            if(aobj == null)
                obj2 = method.invoke(obj, null);
            else
                obj2 = method.invoke(obj, (Object[])aobj[1]);
            if(obj2 == null)
                obj2 = new String("");
        }
        catch(Exception _ex)
        {
            return null;
        }
        return obj2;
    }

    private void clearMemory(String s, String s1)
    {
        if(objects == null)
            return;
        synchronized(objectsLock)
        {
            if(s != null)
            {
                Hashtable hashtable;
                if((hashtable = (Hashtable)objects.get(s)) == null)
                    return;
                hashtable.remove(s1);
            } else
            {
                Hashtable hashtable1;
                for(Enumeration enumeration = objects.elements(); enumeration.hasMoreElements(); hashtable1.remove(s1))
                    hashtable1 = (Hashtable)enumeration.nextElement();

            }
        }
    }

    private int getModificator(String s)
    {
        int i = s.indexOf(" ");
        String s1 = "";
        if(i <= 0)
            return -1;
        s1 = s.substring(0, i);
        if(s1.equals("new"))
            return "new".length();
        if(s1.equals("global"))
            return "global".length();
        if(s1.equals("session"))
            return "session".length();
        if(s1.equals("unique"))
            return "unique".length();
        else
            return -1;
    }

    private boolean reservedWord(String s)
    {
        return reservedWords.get(s) != null;
    }

    private boolean getVariable(HttpServletRequest httpservletrequest, String s, String s1, Hashtable hashtable)
    {
        if(getClassVariable(httpservletrequest, s, s1, hashtable) != null)
            return true;
        if(getObjectVariable(httpservletrequest, s, s1, hashtable) != null)
            return true;
        return getStringVariable(httpservletrequest, s, s1, hashtable) != null;
    }

    private Class getClassVariable(HttpServletRequest httpservletrequest, String s, String s1, Hashtable hashtable)
    {
        Hashtable hashtable1 = hashtable;
        if(s1.equals("global"))
            hashtable1 = global_vars;
        else
        if(s1.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
            if(httpsession == null)
                return null;
            hashtable1 = sessions.getVars(httpsession);
        }
        if(hashtable1 == null)
            return null;
        Object aobj[] = (Object[])hashtable1.get(s);
        if(aobj == null)
            return null;
        else
            return (Class)aobj[0];
    }

    private Object getObjectVariable(HttpServletRequest httpservletrequest, String s, String s1, Hashtable hashtable)
    {
        Hashtable hashtable1 = hashtable;
        if(s1.equals("global"))
            hashtable1 = global_vars;
        else
        if(s1.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
            if(httpsession == null)
                return null;
            hashtable1 = sessions.getVars(httpsession);
        }
        if(hashtable1 == null)
            return null;
        Object aobj[] = (Object[])hashtable1.get(s);
        if(aobj == null)
            return null;
        else
            return aobj[1];
    }

    private String getStringVariable(HttpServletRequest httpservletrequest, String s, String s1, Hashtable hashtable)
    {
        if(s.equals("global"))
        {
            if(global_vars == null)
                return null;
            Object aobj[];
            if((aobj = (Object[])global_vars.get(s1)) == null)
                return null;
            else
                return (String)aobj[2];
        }
        if(s.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
            if(httpsession == null)
                return null;
            Object aobj1[];
            if((aobj1 = sessions.getVar(httpsession, s1)) == null)
                return null;
            else
                return (String)aobj1[2];
        }
        Object aobj2[];
        if(hashtable != null && (aobj2 = (Object[])hashtable.get(s1)) != null)
            return (String)aobj2[2];
        if(s.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession1 = sessions.getSession(httpservletrequest, false);
            if(httpsession1 != null && (aobj2 = sessions.getVar(httpsession1, s1)) != null)
                return (String)aobj2[2];
        }
        if(global_vars == null)
            return null;
        if((aobj2 = (Object[])global_vars.get(s1)) == null)
            return null;
        else
            return (String)aobj2[2];
    }

    private void setVar(HttpServletRequest httpservletrequest, String s, String s1, Class class1, Object obj, String s2, Hashtable hashtable)
    {
        Object aobj[] = {
            class1, obj, prepareString(s2)
        };
        if(s.equals("global"))
        {
            global_vars.remove(s1);
            global_vars.put(s1, ((Object) (aobj)));
            return;
        }
        if(s.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, true);
            if(httpsession != null)
            {
                sessions.setSessionVariable(httpsession, s1, aobj);
                return;
            }
        } else
        {
            setLocalVar(hashtable, s1, ((Object) (aobj)));
        }
    }

    private void setLocalVar(Hashtable hashtable, String s, Object obj)
    {
        hashtable.remove(s);
        hashtable.put(s, obj);
    }

    private String prepareString(String s)
    {
        if(s == null)
            return null;
        if(s.length() < 2)
            return s;
        if(s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"')
            return s.substring(1, s.length() - 1);
        else
            return s;
    }

    private String makeCall(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, String s, String s1, Hashtable hashtable, int ai[])
    {
        String s2 = "";
        String s7 = "";
        String s8 = "";
        String s9 = "";
        String s10 = "";
        Object obj = null;
        String s11 = "";
        String s12 = "";
        String s13 = "";
        int i;
        if((i = s1.indexOf("(")) < 0)
            return "syntax error:" + s1;
        s7 = s1.substring(0, i).trim();
        int l = getModificator(s7);
        if(l > 0)
        {
            s13 = s7.substring(0, l);
            if(s13.equals("global") || s13.equals("session"))
            {
                String s3 = s7.substring(l).trim();
                String s5 = getIdent(s3);
                if(s5.length() > 0)
                {
                    String s6 = s3.substring(s5.length()).trim();
                    if(s6.length() > 0)
                    {
                        if(s6.charAt(0) == '=')
                        {
                            s12 = s5;
                            s7 = s6.substring(1).trim();
                        } else
                        {
                            s13 = "";
                        }
                    } else
                    {
                        s13 = "";
                    }
                } else
                {
                    s13 = "";
                }
            } else
            {
                s13 = "";
            }
        }
        if(s12.length() > 0)
        {
            if(reservedWord(s12))
                return "wrong identificator - reserver word:" + s1;
            if(s7.length() == 0)
                return "wrong expression:" + s1;
        } else
        {
            s12 = getIdent(s7);
            if(s12.length() > 0)
            {
                String s4 = s7.substring(s12.length()).trim();
                if(s4.length() == 0)
                    s12 = "";
                else
                if(s4.charAt(0) == '=')
                {
                    if(reservedWord(s12))
                        return "wrong identificator - reserver word:" + s1;
                    s7 = s4.substring(1).trim();
                    if(s7.length() == 0)
                        return "wrong expression:" + s1;
                } else
                {
                    s12 = "";
                }
            } else
            {
                return "no identificator:" + s7;
            }
        }
        for(int j = getModificator(s7); j > 0; j = getModificator(s7))
        {
            s8 = s8 + s7.substring(0, j) + " ";
            s7 = s7.substring(j).trim();
        }

        if(s8.indexOf("new") < 0)
        {
            int k = s7.lastIndexOf(".");
            if(k <= 0 || k == s7.length() - 1)
                return "cannot load class :" + s7;
            s9 = s7.substring(k + 1);
            s7 = s7.substring(0, k);
        }
        s10 = s1.substring(i);
        s10 = proceedJSPline(httpservletrequest, httpservletresponse, printwriter, s, s10.trim(), hashtable, ai);
        if(s7.equalsIgnoreCase("alaJSP"))
            s7 = "stdlib";
        Class class1;
        if((class1 = getClassVariable(httpservletrequest, s7, s8.trim(), hashtable)) == null)
            class1 = loadClass(httpservletrequest, s8, s7);
        if(class1 == null)
            return "cannot load class :" + s7;
        if(s8.indexOf("global") < 0)
            s11 = s;
        else
            s11 = "";
        if(s8.indexOf("new") >= 0)
        {
            if(s8.indexOf("unique") >= 0)
            {
                obj = getObjectInstance(httpservletrequest, class1, s8, s11);
                if(obj != null)
                {
                    if(s12.length() > 0)
                        setVar(httpservletrequest, s13, s12, class1, obj, null, hashtable);
                    return "";
                }
            }
            if((obj = createObjectInstance(httpservletrequest, s8, class1, s10, s11)) == null)
                return "cannot create object :" + s7;
            if(s12.length() > 0)
                setVar(httpservletrequest, s13, s12, class1, obj, null, hashtable);
            return "";
        }
        if((obj = getObjectInstance(httpservletrequest, class1, s8, s11)) == null)
            return "object does not exist :" + s7;
        if((obj = invokeObject(httpservletrequest, httpservletresponse, printwriter, class1, obj, s9, s10)) == null)
            return "cannot execute method :" + s7 + "." + s9 + s10;
        s2 = obj.toString();
        if(s12.length() > 0)
        {
            setVar(httpservletrequest, s13, s12, class1, obj, s2, hashtable);
            s2 = "";
        }
        return s2;
    }

    private String getAttribute(HttpServletRequest httpservletrequest, String s, String s1, Hashtable hashtable)
    {
        String s2 = s1;
        String s5 = "";
        String s6 = "";
        String s7 = "";
        String s8 = "";
        String s9 = "";
        int i = getModificator(s2);
        if(i > 0)
        {
            s7 = s2.substring(0, i);
            s2 = s2.substring(i).trim();
            if(s2.length() == 0)
                return "wrong expression";
            if(!s7.equals("global") && !s7.equals("session"))
                return "wrong expression";
        }
        s9 = getIdent(s2);
        if(s9.length() != 0)
        {
            String s3 = s2.substring(s9.length()).trim();
            if(s3.length() == 0)
                if((s3 = getStringVariable(httpservletrequest, s7, s9, hashtable)) == null)
                    return "variable does not exist:" + s9;
                else
                    return s3;
            if(s3.charAt(0) == '=')
            {
                s3 = s3.substring(1).trim();
                if(s3.length() == 0)
                    return "wrong expression";
                s2 = s3;
            }
        } else
        if(s7.length() > 0)
            return "wrong expression";
        else
            return s2;
        String s4 = getIdent(s2);
        if(s4.length() == 0)
        {
            setVar(httpservletrequest, s7, s9, null, null, s2, hashtable);
            return "";
        }
        String s10;
        if(s9.length() == 0)
            s10 = s7;
        else
            s10 = "";
        if(s2.startsWith("global "))
        {
            s10 = "global";
            s2 = s2.substring("global".length() + 1);
        }
        if(s2.startsWith("session "))
        {
            s10 = "session";
            s2 = s2.substring("session".length() + 1);
        }
        i = s2.lastIndexOf(".");
        if(i <= 0 && (s4 = getStringVariable(httpservletrequest, s10, s2, hashtable)) != null)
        {
            if(s9.length() > 0)
            {
                setVar(httpservletrequest, s7, s9, null, null, s4, hashtable);
                s4 = "";
            }
            return s4;
        }
        if(i <= 0 || i >= s2.length() - 1)
            return "syntax error :" + s2;
        s5 = s2.substring(0, i);
        s6 = s2.substring(i + 1);
        if(s10.indexOf("global") >= 0)
            s8 = "";
        else
            s8 = s;
        s5 = s5.trim();
        s6 = s6.trim();
        Class class1;
        Object obj;
        if((class1 = getClassVariable(httpservletrequest, s5, s10, hashtable)) != null)
        {
            obj = getObjectVariable(httpservletrequest, s5, s10, hashtable);
        } else
        {
            if((class1 = loadClass(httpservletrequest, s10, s5)) == null)
                return "cannot load class :" + s5;
            if((obj = getObjectInstance(httpservletrequest, class1, s10, s)) == null)
                return "object does not exist :" + s5;
        }
        try
        {
            Field field = class1.getField(s6);
            if((obj = field.get(obj)) == null)
                return "";
        }
        catch(Exception _ex)
        {
            return "cannot get attribute :" + s2;
        }
        if(s9.length() > 0)
        {
            setVar(httpservletrequest, s7, s9, null, null, obj.toString(), hashtable);
            return "";
        } else
        {
            return obj.toString();
        }
    }

    private String deleteObject(HttpServletRequest httpservletrequest, String s, Hashtable hashtable, String s1)
    {
        String s2 = s1;
        String s3 = "";
        if(s2.length() == 0)
            return "wrong syntax: fi without if";
        int i = getModificator(s2);
        if(i > 0)
        {
            s3 = s2.substring(0, i);
            s2 = s2.substring(i).trim();
        }
        if(s3.length() == 0)
        {
            if(hashtable.get(s2) != null)
                hashtable.remove(s2);
            else
                clearMemory(s2, s);
        } else
        if(s3.equals("global"))
        {
            if(global_vars.get(s2) != null)
                hashtable.remove(s2);
            else
                clearMemory(s2, "");
        } else
        if(s3.equals("session"))
        {
            javax.servlet.http.HttpSession httpsession = sessions.getSession(httpservletrequest, false);
            if(httpsession != null)
                sessions.deleteObject(httpsession, s2);
        } else
        {
            return "wrong delete command";
        }
        return "";
    }

    private boolean checkCond(String s)
    {
        String s1 = s.trim();
        byte byte0 = -1;
        if(s1.length() == 0)
            return false;
        if(s1.charAt(0) == '(' && s1.endsWith(")"))
            s1 = s1.substring(1, s1.length() - 1);
        if(s1.length() == 0)
            return false;
        if(s1.charAt(0) == '!')
        {
            s1 = s1.substring(1).trim();
            return s1.compareTo("true") != 0;
        }
        String s2 = getLexem(s1);
        if(s2.length() == s1.length())
            return s2.equalsIgnoreCase("true");
        s1 = s1.substring(s2.length()).trim();
        if(s1.startsWith("=="))
        {
            byte0 = 1;
            s1 = s1.substring(2);
        } else
        if(s1.startsWith("!="))
        {
            byte0 = 2;
            s1 = s1.substring(2);
        } else
        if(s1.startsWith(">="))
        {
            byte0 = 3;
            s1 = s1.substring(2);
        } else
        if(s1.startsWith("<="))
        {
            byte0 = 4;
            s1 = s1.substring(2);
        } else
        if(s1.startsWith(">"))
        {
            byte0 = 5;
            s1 = s1.substring(1);
        } else
        if(s1.startsWith("<"))
        {
            byte0 = 6;
            s1 = s1.substring(1);
        }
        if(byte0 < 0)
            return false;
        s1 = s1.trim();
        if(s1.length() == 0)
            return false;
        s1 = prepareString(s1);
        if(byte0 == 1)
            return s2.equals(s1);
        if(byte0 == 2)
            return !s2.equals(s1);
        if(byte0 == 3)
            return s2.compareTo(s1) >= 0;
        if(byte0 == 4)
            return s2.compareTo(s1) <= 0;
        if(byte0 == 5)
            return s2.compareTo(s1) > 0;
        if(byte0 == 6)
            return s2.compareTo(s1) < 0;
        else
            return false;
    }

    private String getLexem(String s)
    {
        String s1 = s.substring(0, 1);
        String s2 = s.substring(1);
        if(s1.charAt(0) == '"')
            for(; s2.length() > 0; s2 = s2.substring(1))
            {
                if(s2.charAt(0) == '"')
                {
                    s1 = s1 + s2.substring(0, 1);
                    break;
                }
                s1 = s1 + s2.substring(0, 1);
            }

        else
            for(; s2.length() > 0; s2 = s2.substring(1))
            {
                if(s2.startsWith("==") || s2.startsWith("!=") || s2.startsWith("<=") || s2.startsWith(">=") || s2.charAt(0) == '<' || s2.charAt(0) == '>')
                    break;
                s1 = s1 + s2.substring(0, 1);
            }

        return s1.trim();
    }

    private String checkNullCond(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1, Hashtable hashtable)
    {
        String s2 = "";
        String s3 = s1;
        if(s3.startsWith("!"))
        {
            s2 = "!";
            s3 = s3.substring(1).trim();
        }
        if(s3.length() == 0)
            return s2;
        if(s3.startsWith("<%"))
            s3 = s3.substring("<%".length()).trim();
        if(s3.endsWith("%>"))
            s3 = s3.substring(0, s3.length() - "%>".length()).trim();
        if(s3.startsWith("(") && s3.endsWith(")"))
            s3 = s3.substring(1, s3.length() - 1).trim();
        if(s3.length() == 0)
            return s2;
        if(s3.charAt(0) == '=')
        {
            s3 = s3.substring(1).trim();
            if(s3.length() == 0)
                return "";
        }
        if(s3.charAt(0) == '!')
        {
            s2 = s2 + "!";
            s3 = s3.substring(1).trim();
            if(s3.length() == 0)
                return "";
        }
        if(s3.startsWith("null"))
        {
            s2 = s2 + "null";
            s3 = s3.substring("null".length()).trim();
            String s4 = checkNullCond(httpservletrequest, httpservletresponse, s, s3, hashtable);
            if(s4.length() == 0)
                return "";
            else
                return s2 + s4;
        }
        if(!s3.endsWith("null"))
            return "";
        s3 = s3.substring(0, s3.length() - "null".length()).trim();
        String s8 = "";
        if(s3.endsWith("=="))
            s8 = "==";
        else
        if(s3.endsWith("!="))
            s8 = "!=";
        if(s8.length() == 0)
            return "";
        s3 = s3.substring(0, s3.length() - s8.length()).trim();
        if(s3.startsWith("global "))
        {
            s3 = s3.substring("global".length() + 1).trim();
            String s5 = getIdent(s3);
            if(s5.length() == 0)
                return "";
            if(!s5.equals(s3))
            {
                s3 = s3.substring(s5.length()).trim();
                if(s3.length() != 0)
                    return "";
            }
            if(!getVariable(httpservletrequest, s3, "global", hashtable))
                return s2 + "null" + s8 + "null";
            else
                return s2 + "NOT" + "null" + s8 + "null";
        }
        if(s3.startsWith("session "))
        {
            s3 = s3.substring("session".length() + 1).trim();
            String s6 = getIdent(s3);
            if(s6.length() == 0)
                return "";
            if(!s6.equals(s3))
            {
                s3 = s3.substring(s6.length()).trim();
                if(s3.length() != 0)
                    return "";
            }
            if(!getVariable(httpservletrequest, s3, "session", hashtable))
                return s2 + "null" + s8 + "null";
            else
                return s2 + "NOT" + "null" + s8 + "null";
        }
        String s7 = getIdent(s3);
        if(s7.length() == 0)
            return "";
        if(!s7.equals(s3))
        {
            s3 = s3.substring(s7.length()).trim();
            if(s3.length() != 0)
                return "";
        }
        if(!getVariable(httpservletrequest, s3, "", hashtable))
            return s2 + "null" + s8 + "null";
        else
            return s2 + "NOT" + "null" + s8 + "null";
    }

    private String proceedJSP(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, String s, String s1, Hashtable hashtable, int ai[])
    {
        String s2 = s1.trim();
        int i = s2.indexOf("include");
        if(i >= 0 && ai[0] == 0)
        {
            s2 = s2.substring(i + "include".length()).trim();
            i = s2.indexOf("page=");
            if(i >= 0)
            {
                s2 = s2.substring(i + "page=".length()).trim();
                if(s2.length() == 0)
                {
                    return s1;
                } else
                {
                    s2 = prepareString(s2);
                    return readFile(s2.trim());
                }
            }
            if((i = s2.indexOf("file=")) < 0)
                return s1;
            s2 = s2.substring(i + "file=".length()).trim();
            if(s2.length() == 0)
            {
                return s1;
            } else
            {
                s2 = prepareString(s2);
                return proceedJSPfile(httpservletrequest, httpservletresponse, printwriter, s, s2.trim(), hashtable);
            }
        }
        i = s2.indexOf("delete");
        if(i == 0)
            return deleteObject(httpservletrequest, s, hashtable, s2.substring("delete".length()).trim());
        i = s2.indexOf("if");
        if(i == 0)
        {
            String s3 = checkNullCond(httpservletrequest, httpservletresponse, s, s2.substring("if".length()).trim(), hashtable);
            if(s3.length() == 0)
                s3 = proceedJSPline(httpservletrequest, httpservletresponse, printwriter, s, s2.substring("if".length()).trim(), hashtable, ai);
            if(checkCond(s3))
            {
                ai[0] = 0;
                ai[1] = 1;
                return "";
            } else
            {
                ai[0] = 1;
                ai[1] = 1;
                return "";
            }
        }
        if((i = s2.indexOf("else")) == 0)
        {
            if(ai[1] == 0)
                return "wrong syntax: else without if";
            if(ai[0] == 0)
                ai[0] = 1;
            else
                ai[0] = 0;
            ai[1] = 2;
            return "";
        }
        if((i = s2.indexOf("fi")) == 0)
            if(ai[1] == 0)
            {
                return "wrong syntax: fi without if";
            } else
            {
                ai[0] = 0;
                ai[1] = 0;
                return "";
            }
        if(ai[0] == 1)
            return "";
        if(s2.startsWith("="))
            s2 = s2.substring("=".length()).trim();
        if(s2.endsWith(";"))
            s2 = s2.substring(0, s2.length() - 1).trim();
        if(s2.endsWith(")"))
            return makeCall(httpservletrequest, httpservletresponse, printwriter, s, s2, hashtable, ai);
        else
            return getAttribute(httpservletrequest, s, s2, hashtable);
    }

    private String getIdent(String s)
    {
        String s1 = s;
        String s2 = "";
        if(s1.length() == 0)
            return "";
        if(isLetter(s1.charAt(0)))
        {
            s2 = s1.substring(0, 1);
            s1 = s1.substring(1);
        } else
        {
            return "";
        }
        for(; s1.length() > 0; s1 = s1.substring(1))
            if(validChar(s1.charAt(0)))
                s2 = s2 + s1.substring(0, 1);
            else
                return s2;

        return s2;
    }

    private boolean isLetter(char c)
    {
        if(c >= 'A' && c <= 'Z')
            return true;
        return c >= 'a' && c <= 'z';
    }

    private boolean validChar(char c)
    {
        if(isLetter(c))
            return true;
        if(c >= '0' && c <= '9')
            return true;
        return c == '$' || c == '_';
    }

    private int getCloseIndex(String s)
    {
        int k = 0;
        int l = 0;
        String s1 = s;
        int i = s1.indexOf("%>");
        int j = s1.indexOf("<%");
        if(j < 0 || i <= 0 || i < j)
            return i;
        while(s1.length() > 0 && i > 0) 
        {
            if(j < i && j > 0)
            {
                k++;
                l += j + "<%".length();
                s1 = s1.substring(j + "<%".length());
            } else
            {
                if(k == 0)
                    return l + i;
                k--;
                l += i + "%>".length();
                s1 = s1.substring(i + "%>".length());
            }
            i = s1.indexOf("%>");
            j = s1.indexOf("<%");
        }
        if(k > 0)
            return -1;
        else
            return l;
    }

    private String proceedTag(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, String s, String s1, Hashtable hashtable, int ai[])
    {
        StringBuffer stringbuffer = new StringBuffer();
        String s2 = "";
        int i = getCloseIndex(s1);
        if(i <= 0)
        {
            stringbuffer.append(s1);
        } else
        {
            String s3 = s1.substring(0, i);
            stringbuffer.append(proceedJSP(httpservletrequest, httpservletresponse, printwriter, s, s3, hashtable, ai));
            if(s1.length() > i + "%>".length())
                stringbuffer.append(proceedJSPline(httpservletrequest, httpservletresponse, printwriter, s, s1.substring(i + "%>".length()), hashtable, ai));
        }
        return stringbuffer.toString();
    }

    private String proceedJSPline(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, String s, String s1, Hashtable hashtable, int ai[])
    {
        StringBuffer stringbuffer = new StringBuffer();
        int i;
        if((i = s1.indexOf("<%")) >= 0)
        {
            if(i == 0)
                stringbuffer.append(proceedTag(httpservletrequest, httpservletresponse, printwriter, s, s1.substring("<%".length()), hashtable, ai));
            else
                stringbuffer.append(s1.substring(0, i) + proceedTag(httpservletrequest, httpservletresponse, printwriter, s, s1.substring(i + "<%".length()), hashtable, ai));
        } else
        {
            stringbuffer.append(s1);
        }
        return stringbuffer.toString();
    }

    private String proceedJSPfile(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, PrintWriter printwriter, String s, String s1, Hashtable hashtable)
    {
        String s2 = getFullPath(s1);
        String s3 = "";
        String s5 = "";
        StringBuffer stringbuffer = new StringBuffer();
        boolean flag = true;
        int ai[] = new int[2];
        try
        {
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(s2)));
            String s4 = bufferedreader.readLine();
            if(s4.indexOf("<!-- alaJSP passed -->") < 0)
                printwriter.println("<!-- alaJSP passed -->");
            else
                flag = false;
            for(; s4 != null; s4 = bufferedreader.readLine())
            {
                s4 = s4.trim();
                String s6;
                if(s4.startsWith("<!--"))
                    s6 = "";
                else
                if(s4.length() > 0)
                {
                    String s7;
                    if(flag)
                        s7 = proceedJSPline(httpservletrequest, httpservletresponse, printwriter, s, s4, hashtable, ai);
                    else
                        s7 = s4;
                    if(ai[0] != 1 && s7.length() > 0)
                        printwriter.println(s7);
                }
            }

            bufferedreader.close();
        }
        catch(Exception _ex)
        {
            return "can not read file " + s2;
        }
        return stringbuffer.toString();
    }

    public void init(ServletConfig servletconfig)
        throws ServletException
    {
        boolean flag = false;
        Object obj = new Object();
        int ai[] = new int[2];
        super.init(servletconfig);
        global_vars = new Hashtable();
        sessions = new AlaJSPSession();
        reservedWords = new Hashtable();
        reservedWords.put("new", obj);
        reservedWords.put("global", obj);
        reservedWords.put("unique", obj);
        reservedWords.put("session", obj);
        reservedWords.put("delete", obj);
        reservedWords.put("alaJSP", obj);
        reservedWords.put("stdlib", obj);
        reservedWords.put("include", obj);
        reservedWords.put("if", obj);
        reservedWords.put("else", obj);
        reservedWords.put("fi", obj);
        reservedWords.put("true", obj);
        reservedWords.put("false", obj);
        reservedWords.put("null", obj);
        separator = System.getProperty("file.separator");
        NEWLINE = System.getProperty("line.separator");
        if((ADMIN = getInitParameter("admin")) == null)
            ADMIN = "welcome";
        if((CLASS_DIR = getInitParameter("classes")) == null)
            CLASS_DIR = ".";
        if((ROOT_DIR = getInitParameter("root")) == null)
            ROOT_DIR = ".";
        if(!ROOT_DIR.endsWith(separator))
            ROOT_DIR = ROOT_DIR + separator;
        System.out.println("(c) Witframework  mailto: wuxinyang@gmail.com");
        String s = getInitParameter("load");
        if(!flag)
        {
            System.out.println("init: load standard library class stdlib");
            String s1 = getId();
            System.out.println(makeCall(null, null, null, s1, "global new stdlib()", null, ai));
        }
        if(s != null)
        {
            String s2 = getId();
            System.out.println("load global script " + s);
            try
            {
                proceedJSPfile(null, null, new PrintWriter(System.out), s2, s, new Hashtable());
                clearMemory(null, s2);
                return;
            }
            catch(Exception _ex)
            {
                System.out.println("Error detected during the global script loading ...");
            }
            return;
        } else
        {
            return;
        }
    }

    public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        doGet(httpservletrequest, httpservletresponse);
    }

    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        PrintWriter printwriter = httpservletresponse.getWriter();
        String s = "";
        String s2 = "";
        String s4 = "";
        httpservletresponse.setContentType("text/html");
        s = httpservletrequest.getQueryString();
        String s6 = httpservletrequest.getRequestURI();
        if(!s6.endsWith("alaJSP") && !s6.endsWith("alaJSP.class"))
        {
            s = s6;
            int i;
            if((i = s.indexOf("?")) > 0)
                s = s.substring(0, i);
            if(s.startsWith("/"))
                s = s.substring(1);
            s = s.replace('/', separator.charAt(0));
        }
        if(s == null)
            s = "";
        if(s.length() > 0)
        {
            String s3;
            if(s.equals(ADMIN))
            {
                s3 = adminJSP(httpservletrequest);
            } else
            {
                if(s.startsWith(ADMIN + "&"))
                {
                    adminCommand(httpservletrequest);
                    String s1 = HttpUtils.getRequestURL(httpservletrequest).toString();
                    int j;
                    if((j = s1.indexOf("?")) > 0)
                        s1 = s1.substring(0, j);
                    httpservletresponse.sendRedirect(s1 + "?" + ADMIN);
                    return;
                }
                int k;
                if((k = s.indexOf("&")) > 0)
                    s = s.substring(0, k);
                String s5 = getId();
                s3 = proceedJSPfile(httpservletrequest, httpservletresponse, printwriter, s5, s, new Hashtable());
                clearMemory(null, s5);
            }
            printwriter.println(s3);
        } else
        {
            printwriter.println("no data file for alaJSP");
        }
        printwriter.flush();
        printwriter.close();
    }

    private synchronized int[] getRefCount(String s)
    {
        int ai[] = new int[2];
        String s1 = "";
        ai[0] = 0;
        ai[1] = 0;
        synchronized(objectsLock)
        {
            if(objects != null)
            {
                Hashtable hashtable = (Hashtable)objects.get(s);
                if(hashtable != null)
                {
                    for(Enumeration enumeration = hashtable.keys(); enumeration.hasMoreElements();)
                    {
                        String s2 = (String)enumeration.nextElement();
                        if(s2.equals(""))
                            ai[0]++;
                        else
                            ai[1]++;
                    }

                }
            }
        }
        return ai;
    }

    private void adminCommand(HttpServletRequest httpservletrequest)
    {
        String s = httpservletrequest.getQueryString();
        if(s.startsWith(ADMIN + "&"))
        {
            s = s.substring((ADMIN + "&").length());
            if(s.startsWith("reload="))
            {
                s = s.substring("reload=".length());
                unloadClass(s);
                return;
            }
            if(s.startsWith("del="))
            {
                s = s.substring("del=".length());
                clearMemory(s, "");
            }
        }
    }

    private String adminJSP(HttpServletRequest httpservletrequest)
    {
        String s = "";
        long l = 0L;
        String s2 = HttpUtils.getRequestURL(httpservletrequest).toString();
        int i;
        if((i = s2.indexOf("?")) > 0)
            s2 = s2.substring(0, i);
        String s3 = s2 + "?" + ADMIN;
        s = s + "<b><center> alaJSP admin page</center></b>" + NEWLINE;
        s = s + "<br><br>" + NEWLINE;
        s = s + "<table BORDER COLS=5 WIDTH=\"100%\" NOSAVE >" + NEWLINE;
        s = s + "<tr bgcolor=\"CCCCFF\">" + NEWLINE;
        s = s + "<td>Class name</td>" + NEWLINE;
        s = s + "<td>Global instance (yes/no)</td>" + NEWLINE;
        s = s + "<td>Local instances (amount)</td>" + NEWLINE;
        s = s + "<td>Unload class (press yes)</td>" + NEWLINE;
        s = s + "<td>Delete global instances (press yes)</td>" + NEWLINE;
        s = s + "</tr>" + NEWLINE;
        synchronized(classesLock)
        {
            if(classes != null)
            {
                for(Enumeration enumeration = classes.keys(); enumeration.hasMoreElements();)
                {
                    s = s + "<tr ";
                    if(l % 2L == 0L)
                        s = s + "bgcolor=\"FFFFFF\">";
                    else
                        s = s + "bgcolor=\"CCCCCC\">";
                    String s1 = (String)enumeration.nextElement();
                    s = s + "<td nowrap>&nbsp;" + s1 + "</td>";
                    int ai[] = getRefCount(s1);
                    s = s + "<td nowrap>&nbsp;" + (ai[0] <= 0 ? "No" : "Yes") + "</td>";
                    s = s + "<td nowrap>&nbsp;" + ai[1] + "</td>";
                    s = s + "<td nowrap>&nbsp;<a href=\"" + s3 + "&" + "reload=" + s1 + "\">Yes ?</a>" + "</td>";
                    s = s + "<td nowrap>&nbsp;" + (ai[0] <= 0 ? "" : "<a href=\"" + s3 + "&" + "del=" + s1 + "\">Yes ?</a>") + "</td>";
                    s = s + "</tr>" + NEWLINE;
                    l++;
                }

            }
        }
        s = s + "</table>" + NEWLINE;
        s = s + "<br><br>&nbsp;&nbsp;  (c) Witframework  mailto: wuxinyang@gmail.com" + NEWLINE;
        return s;
    }

    private String getFullPath(String s)
    {
        if(s.startsWith(separator))
            return s;
        if(separator.charAt(0) == '\\' && s.indexOf(":") > 0)
            return s;
        else
            return ROOT_DIR + s;
    }

    public String getServletInfo()
    {
        return "JSP similar processor servlet (c) Witframework  mailto: wuxinyang@gmail.com ";
    }

    public AlaJSP()
    {
    }

    public static Object SessionIdLock = new Object();
    public static Object objectsLock = new Object();
    public static Object classesLock = new Object();
    private static final String VERSION = "ver. 1.1";
    private static final String CPR = " (c) Witframework  mailto: wuxinyang@gmail.com ";
    private static final int HOW_LONG = 6;
    private static final String MARK = "<!-- alaJSP passed -->";
    private static final String COMMENT = "<!--";
    private static final String BEGIN = "<%";
    private static final String END = "%>";
    private static final String EXPR = "=";
    private static final String INCLUDE = "include";
    private static final String FILE = "file=";
    private static final String PAGE = "page=";
    private static final String IF_EXPR = "if";
    private static final String ELSE_EXPR = "else";
    private static final String FI_EXPR = "fi";
    private static final String DELETE = "delete";
    private static final int PARSE_LINES = 0;
    private static final int SKIP_LINES = 1;
    private static final int WAIT_NOTHING = 0;
    private static final int WAIT_ELSE = 1;
    private static final int WAIT_FI = 2;
    private static final String ALAJSP = "alaJSP";
    private static final String STDLIB = "stdlib";
    private static final String CLASSNAME = "alaJSP";
    private static final String ID = "ID";
    private static final String IP = "IP";
    private static final String ERROR1 = "syntax error";
    private static final String ERROR2 = "cannot load class ";
    private static final String ERROR3 = "cannot create object ";
    private static final String ERROR4 = "object does not exist ";
    private static final String ERROR5 = "cannot execute method ";
    private static final String ERROR6 = "syntax error ";
    private static final String ERROR7 = "cannot get attribute ";
    private static final String ERROR8 = "can not execute standard call";
    private static final String ERROR9 = "no identificator";
    private static final String ERROR10 = "wrong identificator - reserver word";
    private static final String ERROR11 = "wrong expression";
    private static final String ERROR12 = "wrong syntax: else without if";
    private static final String ERROR13 = "wrong syntax: fi without if";
    private static final String ERROR14 = "wrong delete command";
    private static final String ERROR15 = "variable does not exist";
    private static final String NULL = "null";
    private static final String ADMIN_SETUP = "admin";
    private static String ADMIN = "welcome";
    private static final String CLASS_SETUP = "classes";
    private static String CLASS_DIR = ".";
    private static final String ROOT_SETUP = "root";
    private static String ROOT_DIR = ".";
    private static final String LOAD_SETUP = "load";
    private static final String RELOAD_CLASS = "reload=";
    private static final String DELETE_GLOBAL = "del=";
    private static String separator = "/";
    private static String NEWLINE = "\n";
    private static final String GLOBAL = "global";
    private static final String NEW = "new";
    private static final String UNIQUE = "unique";
    private static final String SESSION = "session";
    private static final String GLOBALID = "";
    static Hashtable classes = null;
    static Hashtable objects = null;
    static Hashtable global_vars = null;
    static Hashtable reservedWords = null;
    static AlaJSPSession sessions = null;
    private static final int TYPES = 0;
    private static final int VALUES = 1;
    private static final int DIM = 2;

}
